package com.example.testhiber.initPackage.business.controller;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.awt.*;
import java.io.File;
import java.util.concurrent.ArrayBlockingQueue;

@Controller
@RequestMapping("system")
public class SystemController {
    private static final Logger logger = LoggerFactory.getLogger(SystemController.class);
    private static final String PATH="/system/";

    @Autowired
    private HttpServletRequest request;

    /**
     * 读取某个文件夹下面所有的文件目录
     * @return
     */
    @RequestMapping("/readPictures")
    public ModelAndView readPictures(){
        ModelAndView mav = new ModelAndView();



        mav.setViewName(PATH+"picture");
        return mav;
    }

    /**
     * 读取某个文件夹下面所有的文件目录
     * @return
     */
    @ResponseBody
    @RequestMapping("/menus")
    public String menus(){
        String res = "{\"data\":[{\"id\":125,\"authName\":\"用户管理\",\"path\":\"users\",\"children\":[{\"id\":110,\"authName\":\"用户列表\",\"path\":\"users\",\"children\":[],\"order\":null}],\"order\":1},{\"id\":103,\"authName\":\"权限管理\",\"path\":\"rights\",\"children\":[{\"id\":111,\"authName\":\"角色列表\",\"path\":\"roles\",\"children\":[],\"order\":null},{\"id\":112,\"authName\":\"权限列表\",\"path\":\"rights\",\"children\":[],\"order\":null}],\"order\":2},{\"id\":101,\"authName\":\"商品管理\",\"path\":\"goods\",\"children\":[{\"id\":104,\"authName\":\"商品列表\",\"path\":\"goods\",\"children\":[],\"order\":1},{\"id\":115,\"authName\":\"分类参数\",\"path\":\"params\",\"children\":[],\"order\":2},{\"id\":121,\"authName\":\"商品分类\",\"path\":\"categories\",\"children\":[],\"order\":3}],\"order\":3},{\"id\":102,\"authName\":\"订单管理\",\"path\":\"orders\",\"children\":[{\"id\":107,\"authName\":\"订单列表\",\"path\":\"orders\",\"children\":[],\"order\":null}],\"order\":4},{\"id\":110,\"authName\":\"文件夹管理\",\"path\":\"folder\",\"children\":[{\"id\":159,\"authName\":\"文件夹管理\",\"path\":\"folder\",\"children\":[],\"order\":null}],\"order\":6},{\"id\":145,\"authName\":\"数据统计\",\"path\":\"reports\",\"children\":[{\"id\":146,\"authName\":\"数据报表\",\"path\":\"reports\",\"children\":[],\"order\":null}],\"order\":5}],\"meta\":{\"msg\":\"获取菜单列表成功\",\"status\":200}}";
        return res;
    }



    /**
     * 打开文件目录
     * @return
     */
    @RequestMapping("/initPicture")
    public void initPicture(){

        try {
            System.out.println(Desktop.isDesktopSupported());
            System.setProperty("java.awt.headless", "false");
            // 先判断当前平台是否支持桌面
            if (Desktop.isDesktopSupported()) {
                // 获取当前平台桌面实例
                Desktop desktop = Desktop.getDesktop();

                // 使用默认浏览器打开链接
                //            desktop.browse(URI.create("https://blog.csdn.net/xietansheng"));

                // 打开指定文件/文件夹
//                desktop.open(new File("C:\\"));

                Desktop.getDesktop().open(new File("D:"+ File.separator +"resource"));

            } else {
                System.out.println("当前平台不支持 Desktop");
            }
        }catch (Exception e){
        }

    }

    public static void main(String[] args) {
        try {
            Desktop.getDesktop().open(new File("D:"+ File.separator +"resource"));
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public static void openFile(){
        try {
            Desktop.getDesktop().open(new File("D:"+ File.separator +"resource"));
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}

